<?php
namespace App\Http\Middleware;

use Closure;
use Auth;

class AdminPermissionCheck {

    /**
     * Run the request filter.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::user()->role != config("constants.user.role.manager")){
            if ($request->ajax()) {
                return response('Unauthorized!', 401);
            } else {
                abort(404);
            }
        }

        return $next($request);
    }

}